import unittest
from api.base.sys.user.saveorupdate import SaveOrUpdate
from data.queryRolePage_data import QueryRolePageData
from api.base.sys.user.queryInfoPage import QueryInfoPage
from api.base.sys.user.removeOpById import RemoveOpById
from ddt import ddt, data, unpack

create_user = SaveOrUpdate()

que = QueryRolePageData()

query = QueryInfoPage()

remove = RemoveOpById()


@ddt
class QueryRolePage1(unittest.TestCase):
    def setUp(self):
        pass

    @data(*que.save_data)
    def test_01_create_user(self, women):
        """创建用户，输入账号、昵称、邮箱、个人角色：admin，普通用户"""
        a = create_user.save(*women)
        print(a)
        self.assertEqual(a['success'], True, '创建失败')
        b = query.query_user(women[0])['data']['data']
        # print(b)
        c = None
        for i in b:
            if i['op']['shortName'] == women[0] and i['op']['opName'] == women[1] \
                    and i['op']['emailAdress'] == women[2] \
                    and i['roles'][0]['roleName'] == women[7] \
                    and i['roles'][1]['roleName'] == women[8]:
                c = '断言成功'
                break
        self.assertEqual(c, '断言成功', '断言失败！')

    @data(que.save_data1)
    def test_02_create_user(self, women):
        """账号名称、昵称、邮箱、电话、即时通讯、描述、所属组织、个人角色:'admin','普通用户'"""
        a = create_user.save(*women)
        print(a)
        self.assertEqual(a['success'], True, '创建失败')
        b = query.query_user(women[0])['data']['data']
        # print(b)
        c = None
        for i in b:
            if i['op']['shortName'] == women[0] and i['op']['opName'] == women[1] \
                    and i['op']['emailAdress'] == women[2] \
                    and i['op']['mobileNo'] == women[3]\
                    and i['op']['imAccount'] == women[4]\
                    and i['op']['notes'] == women[5]\
                    and i['roles'][0]['roleName'] == women[7] \
                    and i['roles'][1]['roleName'] == women[8]:
                c = '断言成功'
                break
        self.assertEqual(c, '断言成功', '断言失败！')

    @data(que.save_data1,*que.save_data)
    def test_02_remove_user(self, delete):
        """删除创建的用户"""

        a = remove.remove_user(delete[0])
        print(a)
        self.assertEqual(a['success'], True, '删除失败！')
        b = query.query_user(delete[0])
        self.assertEqual(b['data']['data'], [], '断言失败！')


if __name__ == '__main__':
    runner = unittest.TextTestRunner()
    suite = unittest.makeSuite(QueryRolePage1)
    runner.run(suite)
